﻿using System;
using System.Collections.Generic;
using System.Text;

namespace RouterControl.WhsAddIn
{
	public static class FormatHelpers
	{
		// http://dotnet-snippets.de/dns/create-nice-file-size-in-c-SID906.aspx
		public static string GetNiceFileSize(long size)
		{
			int run = 0;
			double d = Convert.ToDouble(size);

			string[] sizes = { "B", "KB", "MB", "GB" };

			while ((d >= 1024.0) && (run < sizes.Length - 1))
			{
				d /= 1024.0;
				run++;
			}

			double dou = Math.Round(d, 2);
			string sizestring = dou.ToString();

			return (sizestring + " " + sizes[run]);
		}

		public static string GetNiceDataRate(long rate)
		{
			int run = 0;
			double d = Convert.ToDouble(rate);

			string[] sizes = { "b", "Kb", "Mb", "Gb" };

			while ((d >= 1024.0) && (run < sizes.Length - 1))
			{
				d /= 1024.0;
				run++;
			}

			double dou = Math.Round(d, 2);
			string sizestring = dou.ToString();

			return (sizestring + " " + sizes[run] + "/s");
		}

		public static string GetNiceTimeSpan(TimeSpan ts)
		{
			return string.Format(
				Properties.Resources.txtNiceTimeSpan,
				ts.Days,
				ts.Hours,
				ts.Minutes,
				ts.Seconds,
				ts.Milliseconds
				);
		}
	}
}
